﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;
using CommonTagTime;

public partial class UserControl_Banner : System.Web.UI.UserControl
{
    public string strEffect = string.Empty;
    public string result;
    public string effect = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BannerCollection banners = GetData();

            if (banners != null && banners.Count > 0)
            {
                foreach (CommonTagTime.ModelObject.Banner banner in banners)
                {
                    //check file Exist
                    string path = Server.MapPath("~/" + clsConfigData.DEFAULT_UPLOAD_BANNER_FOLDER);
                    if (System.IO.File.Exists(path + banner.FilePath))
                    {
                        result += @"<li><a href='" + banner.Url + @"' title='' target='_self'>
                        <img src='/" + clsConfigData.DEFAULT_UPLOAD_BANNER_FOLDER + banner.FilePath + "' alt=''/></a></li>";

                    }
                }


            }
            LoadEffect();
        }
    }


    public BannerCollection GetData()
    {
        //get Condition
        busBanner _busBanner = new busBanner();
        CommonTagTime.ModelObject.Banner objLogo = new CommonTagTime.ModelObject.Banner();
        objLogo.CurrentPage = 1;
        objLogo.OrderBy = busBanner.SortOrder;
        objLogo.OrderDirection = "ASC";
        objLogo.PageSize = int.MaxValue;
        objLogo.Condition = " b.IsActive=1";
        DateTime dtNow = clsDateTime.Now;
        objLogo.Condition += " and datediff(day,b.StartingDate,'" + clsConvert.String(dtNow) + "')>=0";
        objLogo.Condition += " and datediff(day,'" + clsConvert.String(dtNow) + "',b.EndingDate)>=0";
        return _busBanner.List(objLogo);
    }

    public void LoadEffect()
    {
        effect = string.Empty;
        busBannerSlideConfig _bus = new busBannerSlideConfig();
        BannerSlideConfigCollection lstEffect = _bus.GetAll();
        foreach (BannerSlideConfig item in lstEffect)
        {
            effect += "'" + item.SlideEffect + "',";
        }
        if (effect.Length > 0)
        {
            effect = effect.Substring(0, effect.Length - 1);
            effect = "[" + effect + "]";
        }
        else effect = "'fade'";

    }
}